package com.informationsystem.model;

import com.informationsystem.model.BaseObject;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="log")
@Indexed
@XmlRootElement
public class Log extends BaseObject implements Serializable {
    private Long id;
    private Systemuser systemuser;
    private Date logDate = new Date();
    private String actionDetails;

    @Id @GeneratedValue(strategy=IDENTITY) @DocumentId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="user_id", nullable=false)
    public Systemuser getSystemuser() {
        return this.systemuser;
    }
    
    public void setSystemuser(Systemuser systemuser) {
        this.systemuser = systemuser;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="log_date", nullable=false, length=10)
    @Field
    public Date getLogDate() {
        return this.logDate;
    }
    
    public void setLogDate(Date logDate) {
        this.logDate = logDate;
    }
    
    @Column(name="action_details", length=200)
    @Field
    public String getActionDetails() {
        return this.actionDetails;
    }
    
    public void setActionDetails(String actionDetails) {
        this.actionDetails = actionDetails;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Log pojo = (Log) o;

        if (systemuser != null ? !systemuser.equals(pojo.systemuser) : pojo.systemuser != null) return false;
        if (logDate != null ? !logDate.equals(pojo.logDate) : pojo.logDate != null) return false;
        if (actionDetails != null ? !actionDetails.equals(pojo.actionDetails) : pojo.actionDetails != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (systemuser != null ? systemuser.hashCode() : 0);
        result = 31 * result + (logDate != null ? logDate.hashCode() : 0);
        result = 31 * result + (actionDetails != null ? actionDetails.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("systemuser").append("='").append(getSystemuser()).append("', ");
        sb.append("logDate").append("='").append(getLogDate()).append("', ");
        sb.append("actionDetails").append("='").append(getActionDetails()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
